# Identifying Price Informativeness -- Davila/Parlatore, 2024
# Code modified by Dean Parker

library(here)
path <- here::here(); print(path); setwd(path); rm(path)

# Set flag to download raw data
download_data <- T

if (!file.exists("output/")){ 
  dir.create("output/") 
  dir.create("input/") 
  dir.create("intermediate/") 
}

if(download_data){
  source("import_data/00_import_all.R")
}

# Runs the main files ----
# 
rmarkdown::render("00a_set_run_parameters.Rmd");              rm(list = ls());
rmarkdown::render("01a_stocks_clean_crsp.Rmd");               rm(list = ls());
rmarkdown::render("01b_stocks_clean_compustat.Rmd");          rm(list = ls());
rmarkdown::render("01c_stocks_inst_ownership.Rmd");           rm(list = ls());
rmarkdown::render("01d_stocks_analyst_coverage.Rmd");         rm(list = ls());
rmarkdown::render("02_stocks_merge.Rmd");                     rm(list = ls());
rmarkdown::render("03_stocks_select.Rmd");                    rm(list = ls());
rmarkdown::render("04a_stocks_recover.Rmd");                  rm(list = ls());
rmarkdown::render("04b_stocks_recover_clean.Rmd");            rm(list = ls());
rmarkdown::render("05a_paper_figures.Rmd");                   rm(list = ls());
rmarkdown::render("05b_paper_tables.Rmd");                    rm(list = ls());
rmarkdown::render("06_generate_csv.Rmd");                     rm(list = ls());

# Moves the html files to the output folder ----

if (!file.exists("output/html_code/")){ 
  dir.create("output/html_code/") 
}

files_to_move <- list.files(path = ".", pattern = "*.html", full.names = FALSE, recursive = FALSE)
file.copy(from = files_to_move, to = "output/html_code")
file.remove(files_to_move)

sessionInfo()
